﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BKH.BLL
{
    class BoNhiemBUO:IBUO<tbl_User>
    {
        HospitalDBDataContext context = new HospitalDBDataContext();
        public bool Insert(tbl_User obj)
        {
            try
            {
                context.tbl_Users.InsertOnSubmit(obj);
                context.SubmitChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }
        }

        public bool Delete(int id)
        {
            try
            {
                tbl_User item = context.tbl_Users.Where(n => n.NhanVienID == id).ToList<tbl_User>().FirstOrDefault();
                if (item !=null)
                {
                    context.tbl_Users.DeleteOnSubmit(item);
                    context.SubmitChanges();
                    return true;
                }
                else
                    return false;

            
                    
            

            }
            catch (Exception)
            {
                
                throw;
            }
        }

        public bool Delete(tbl_User obj)
        {
            throw new NotImplementedException();
        }

        public List<tbl_User> GetAll()
        {
            throw new NotImplementedException();
        }

        public tbl_User GetSingle(int id)
        {
            return context.tbl_Users.Where(n => n.id_User == id).ToList<tbl_User>().FirstOrDefault();
        }

        public bool Update(int id, tbl_User obj)
        {
            try
            {
                tbl_User i = context.tbl_Users.Where(n => n.NhanVienID == id).ToList<tbl_User>().FirstOrDefault();
                i.UserName = obj.UserName;
                i.Id_Quyen = obj.Id_Quyen;
                i.Password = obj.Password;
                context.SubmitChanges();
                return true;



            }
            catch (Exception)
            {

                return false;
            }
        }
        public tbl_User SelectUserByIDNhanVien(int IDNV)
        {
            return context.tbl_Users.Where(n => n.NhanVienID == IDNV).ToList<tbl_User>().FirstOrDefault();
        }

      
    }
}
